<?php
error_reporting(0);
require_once("includes/pagetop.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$patharr=explode("/",$_SERVER["REQUEST_URI"]);

$lastvars=end($patharr);

$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);
if(!(isset($_REQUEST['t']) && trim($_REQUEST['t'])!=''))
{
    redirect("home.php");
}

$dnauserqry="select * from af_users where Allyfolio_User_ID=:afuserid  ";
$condition[":afuserid"]=$_REQUEST['t'];
$dnauserinfo=$pdodbobj->fetch_array($pdodbobj->query($dnauserqry,$condition));

if(count($dnauserinfo)==0)
{
    redirect($_SERVER["HTTP_REFERER"]);
}

//echo "<pre>";
//print_r($dnauserinfo);
//echo "</pre>";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | DNA </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>

<script src="js/functions.js"></script>

<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>


<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>



<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	}

	.new tr td{ vertical-align:top}

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

	

</style>

</head>

<body>
	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<div class="wrapper row1">
    
    <?php
    require_once("includes/dnaheader.php");
    
    $condition=array();
    $allentertainmentsquery="select id,title,image_url,link,small_description,total_pics,avg_rating,status,added_by from af_entertainments where added_by=:addedby order by added_date desc  ";
    $condition[":addedby"]=$dnauserinfo[0]['User_ID'];
    
    $allentertainmentsinfo=$pdodbobj->fetch_array($pdodbobj->query($allentertainmentsquery,$condition));
    
    ?>
    <div class="clearfix"></div>  

    </div>

    <div class="clearfix"></div>

    <!--=================Header end=======================-->

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <?php include_once("dna_top.php"); ?>

 
<input type="hidden" name="loggedinuserid" id="loggedinuserid" value="<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>" />

<?php

if(count($allentertainmentsinfo)>0)
{
?>
<form name="entform" method="post" action="dna_entertainment.php?t=<?php echo $_REQUEST['t']; ?>">
<div class="dna_nav" style="margin-top:10px; text-align:center;">

		   Entertainment

			<div style="clear:both;"></div>

		   </div>

        <div class="clearfix"></div>

		<table width="100%" border="0" cellpadding="0" cellspacing="0">
        <?php
        
        
        $starcount=0;
        for($j=0;$j<count($allentertainmentsinfo);$j++)
        {
            if($j%4==0)
            {
                echo "<tr>";
            }
            
            $remaintd=0;
            
            if(($j+1)==count($allentertainmentsinfo))
            {
                $remaintd=4-(($j+1)%4);
            }
            
            if(!(strpos($allentertainmentsinfo[$j]['link'],"http://")>=0))
            {
                $allentertainmentsinfo[$j]['link']="http://".$allentertainmentsinfo[$j]['link'];
            }
                                                
            ?>
            <td>

    			<div class="box4">
                    <a href="javascript:void(0);" onclick="return updateEntPickcounter(<?php echo $allentertainmentsinfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $allentertainmentsinfo[$j]['link']; ?>',<?php echo $starcount; ?>);">
                        <img src="<?php echo "uploads/entertainments/".$allentertainmentsinfo[$j]['image_url']; ?>" width="166px" height="116px" />
                    </a>
                    <?php if($_SESSION['Allyfolio_User_ID']==$allentertainmentsinfo[$j]['added_by']){ 
                                    ?>
                        <span style="position: relative;float: right;margin-right:5px;font-size:14px;color: red;">
                        <a href="javascript:void(0);" onclick="return changeEntertainment(<?php echo $allentertainmentsinfo[$j]['id']; ?>);">X</a>
                        </span>
                        <?php
                        }
                        ?>
    				<div class="abs">
    
    					<span class="dna_name">
                            <a href="javascript:void(0);" onclick="updateEntPickcounter(<?php echo $allentertainmentsinfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $allentertainmentsinfo[$j]['link']; ?>',<?php echo $starcount1; ?>);">
                                <?php echo $allentertainmentsinfo[$j]['title']; ?>
                            </a>
                        </span>
                        
    					<span class="dna_check">
                            Pick : <span class="num" id="pick_ent_<?php echo $starcount; ?>"><?php echo $allentertainmentsinfo[$j]['total_pics']; ?></span>
    
    					</span>
    
    				</div>
    
    			</div>
            </td>
            <?php
            $starcount++;  
            if($remaintd>0)
            {
                echo "<td colspan='".$remaintd."'><div class='box4'></div></td>";
            }
            if(($j+1)%4==0)
            {
                echo "</tr>";
            }
        }
        ?>
</table>
</form>
<?php
}
?>

 <div class="clearfix"></div>

       </div>  
       
</div>

    </div>

    <div class="clearfix"></div>

    <!--=================Body Contain end=======================-->

    </div>

 <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[
    function updatePickcounter(appid,userid,linkval,starcountid)
    {
        if(userid==0)
        {
            alertify.alert('Please login first to pick the app.');
            return false;
        }
        else
        {
            $.ajax({
              cache:false,  
        	  url: "ajax_search/ajax_manageapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
        	  success: function( data ) {
        	    if(parseInt(data)>=0)
                {
                    document.getElementById('pick'+starcountid).innerHTML=trim(parseInt(data).toString());
                    window.open(linkval);
                    return false;
                }
                else
                {
                    alertify.alert("There is an error in picking the app.");
                    return false;
                }
        	  }
        	});
        }
    }
    
    
    function updateEntPickcounter(appid,userid,linkval,starcountid)
    {
        if(userid==0)
        {
            alertify.alert('Please login first to pick the entertainment link.');
            return false;
        }
        else
        {
            $.ajax({
              cache:false,  
        	  url: "ajax_search/ajax_manageentapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
        	  success: function( data ) {
        	    if(parseInt(data)>=0)
                {
                    document.getElementById('pick_ent_'+starcountid).innerHTML=trim(parseInt(data).toString());
                    window.open(linkval);
                    return false;
                }
                else
                {
                    alertify.alert("There is an error in picking the entertainment link.");
                    return false;
                }
        	  }
        	});
        }
    }
    
    function viewEventInfo(evtid,flag)
    {
        document.getElementById(['event_id']).value=evtid;
        if(evtid!="")
        {
            if(flag==0)
            {
                document.eventform.action='event_details.php';
                document.getElementById('actiontype').value="";
            }
            else
            {
                document.getElementById('actiontype').value="editeventinfo";    
            }
            
            document.eventform.submit();
        }
    }
    
    function changeEntertainment(entid)
    {
        if(entid>0)
        {
            alertify.confirm("Are you sure, you want to delete Entertainment?", function (e) {
        		if (e) {
        			alertify.success("You've clicked OK");
        			$.ajax({
                      cache:false,  
                      async:false,
                      url: "ajax_search/ajax_manageRequests.php?action=deleteEntertainment&entid="+entid,
                	  success: function( data ) {
                	    if(trim(data)=="success")
                        {
                            alertify.alert("You have successfully delete event.");
                            if(document.getElementById('alertify-cover'))
                            {
                                document.getElementById('alertify-cover').style.display='none';
                            }
                            document.entform.action='dna_entertainment.php?t=<?php echo $_REQUEST['t']; ?>';
                            document.entform.submit();
                        }
                        
                	  }
                	});
        		} else {
        			alertify.error("You've clicked Cancel");
        		}
        	});
         }
    }
    
//]]>
</script>